package com.childenglish.mapper;

import com.childenglish.entity.SysRolePermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysRolePermissionMapper {

    @Select("SELECT * FROM sys_role_permission WHERE role_id = #{roleId}")
    List<SysRolePermission> findByRoleId(Long roleId);

    @Select("SELECT p.* FROM sys_role_permission p " +
            "JOIN sys_user_role ur ON p.role_id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<SysRolePermission> findByUserId(Long userId);

    @Insert("INSERT INTO sys_role_permission(role_id, permission_code, permission_name, create_time) " +
            "VALUES(#{roleId}, #{permissionCode}, #{permissionName}, NOW())")
    int insert(SysRolePermission permission);

    @Delete("DELETE FROM sys_role_permission WHERE role_id = #{roleId}")
    int deleteByRoleId(Long roleId);

    @Delete("DELETE FROM sys_role_permission WHERE id = #{id}")
    int deleteById(Long id);
}